from cgi import print_directory
import os
import sys
from functools import reduce
"""
a1:  区间值模糊数 格式为([],[])

self.q: q值
self.x: 一个参数时所用的变量

a2:     区间值模糊数 格式为([],[])

编写时间:2022-6-28 
编写人:吴卓成
参考文献:Multi‑attribute decision making using q‑rung orthopair fuzzy weighted fairly aggregation operators
注意 目前只有乘法与数乘  
"""

from Utilities.AutoGetOperator.selectPackage import get_func

Operator_IVQ_ROFS=get_func(r'Operators/OperationOperators/OperatorIVQROF.py','Operator_IVQ_ROFS')

class WeightedFairlyAggregationOperators(Operator_IVQ_ROFS):
    def multi(self,a1,a2,q=0,*waste1, **waste2):
        u_1_f, u_1_r, v_1_f, v_1_r = *a1[0], *a1[1]
        u_2_f, u_2_r, v_2_f, v_2_r = *a2[0], *a2[1]
        if q <= 0:
            q = self.q
        u_f=(((u_1_f**q)*(u_2_f**q) / ((u_1_f**q)*(u_2_f**q) +(v_1_f**q)*(v_2_f**q) )) * (1-((1-(u_1_f**q)-(v_1_f**q)) * (1-(u_2_f**q)-(v_2_f**q))))) ** (1/q)
        u_r=(((u_1_r**q)*(u_2_r**q) / ((u_1_r**q)*(u_2_r**q) +(v_1_r**q)*(v_2_r**q) )) * (1-((1-(u_1_r**q)-(v_1_r**q)) * (1-(u_2_r**q)-(v_2_r**q))))) ** (1/q)
        v_f=(((v_1_f**q)*(v_2_f**q) / ((u_1_f**q)*(u_2_f**q) +(v_1_f**q)*(v_2_f**q) )) * (1-((1-(u_1_f**q)-(v_1_f**q)) * (1-(u_2_f**q)-(v_2_f**q))))) ** (1/q)
        v_r=(((v_1_r**q)*(v_2_r**q) / ((u_1_r**q)*(u_2_r**q) +(v_1_r**q)*(v_2_r**q) )) * (1-((1-(u_1_r**q)-(v_1_r**q)) * (1-(u_2_r**q)-(v_2_r**q))))) ** (1/q)
        return ([u_f, u_r], [v_f, v_r])
    def kmulti(self,a1,q=0,t=0,*waste1, **waste2):
        """
         function: 区间值广义正交模糊数的数乘

        a1  :     参上
        a2  :     参上
        q   :     参数
        p   :     参数
        t   :     数乘的数
        return  : 返回模糊数数乘的结果 依旧是一个模糊数
        """
        u_1_f, u_1_r, v_1_f, v_1_r = *a1[0], *a1[1]
        if q <= 0:
            q = self.q
        u_f=((((u_1_f**q)**t)/(((u_1_f**q)**t)+((v_1_f**q)**t))) * (1-((1-(u_1_f**q)-(v_1_f**q))**t)))**(1/q)
        u_r=((((u_1_r**q)**t)/(((u_1_r**q)**t)+((v_1_r**q)**t))) * (1-((1-(u_1_r**q)-(v_1_r**q))**t)))**(1/q)
        v_f=((((v_1_f**q)**t)/(((u_1_f**q)**t)+((v_1_f**q)**t))) * (1-((1-(u_1_f**q)-(v_1_f**q))**t)))**(1/q)
        v_r=((((v_1_r**q)**t)/(((u_1_r**q)**t)+((v_1_r**q)**t))) * (1-((1-(u_1_r**q)-(v_1_r**q))**t)))**(1/q)
        return ([u_f, u_r], [v_f, v_r])
    def getResult(self, *waste1, **waste2):
        data_list=self.data_list
        weight_list=self.weight_list
        res=self.kmulti(self.data_list[0],self.q,self.x,self.weight_list[0])#取出第一个W*AI为结果初始值
        data_list=data_list[1::]#切片获取除去第一个元素以外的其他元素
        for index, enum in enumerate(data_list,start=1):
            temp=self.kmulti(enum,self.q,weight_list[index])
            res=self.multi(res,temp,self.q)
        return res            
if __name__ == '__main__':
    data_list=[([0.31, 0.24], [0.73, 0.72]), ([0.97, 0.12], [0.12, 0.05]),
    ([0.8, 0.52], [0.73, 0.15]), ([0.91, 0.49], [0.42, 0.47]),([0.95, 0.06], [0.19, 0.1])]
    weight_list=[0.1, 0.2, 0.3, 0.1, 0.3],
    Pa =WeightedFairlyAggregationOperators(data_list)
    # Pa = GA(list1)
    # Pa = WA(list1,weight_list)
    # Pa = WGA(list1,weight_list)
    # Pa = OWA(list1,weight_list)
    print(Pa.getResult())
   